-
Notifications
You must be signed in to change notification settings - Fork 0
fix(recipe): protect recipe edits from conflicts, leaving and sign-out #124
Merged
+659
−27
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- updateRecipe takes an optional expectedUpdatedAt. The editor sends the version it loaded; if the recipe changed since (another tab or device) the API refuses with CONFLICT under the row lock, and the form keeps the user's changes with an explanation of how to keep them. - Unsaved changes (form differs from how it opened and from the draft in this browser) trigger the browser's prompt on reload/close and, through a data router (createBrowserRouter) and useBlocker, a Leave/Stay dialog for in-app navigation. A successful save navigates away unasked. - Sign-out asks first when it would delete saved drafts or close the editor with unsaved changes, and says which. - Save draft asks before replacing a draft that was offered but not restored or discarded, or that another tab saved meanwhile. - After logging in from /recipes/<id>/edit the user returns to that editor (strict UUID pattern, no other paths). Closes #121
The redirect test waited 1 s (the default) for the lazy-loaded Log in page. As the file's first test it pays the cold import, which took 1.6 s on the CI runner once the header imported the confirmation dialog. Refs #121
Confirming sign-out clears the shared unsaved flag so the editor does not ask again while it closes. If sign-out then failed, the flag stayed off and the editor's leave and reload prompts were disabled for the rest of the session. The previous value is now restored on failure. Refs #121
|
Two follow-up commits after opening this PR:
|
olestan
approved these changes
Nov 17, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved. Consider making these improvements:
- Pending images (
RecipeCreatePage.tsx:229–230): Selecting an image without changing other fields doesn't mark the form as unsaved. Reloading can discard pending image work without warning. - Draft data loss (
RecipeCreatePage.tsx:229–230): If another tab replaces or deletes a saved draft, the editor still considers the form saved. Users can leave without a warning and lose their changes. The dirty state should account for external draft changes.
# Conflicts: # apps/web/src/features/recipes/RecipeCreatePage.test.tsx # apps/web/src/features/recipes/RecipeCreatePage.tsx # scripts/test-recipe-api.ts
…where Choosing an image opens the crop dialog and uploads it later, and until then nothing in the form differs, so reloading or leaving discarded the pending image without a warning. A picked image that is not uploaded yet now counts as an unsaved change. The editor also remembered the draft it had saved or restored and treated the form as kept for good. If another tab replaced or deleted that draft, leaving still passed without a warning and the changes were lost. It now reads the draft stored in this browser whenever it changes (storage event, saving, discarding) and compares the form against that.
The test types and drags through the whole form and took about 4.95 s on the CI runner against vitest's 5 s default, timing out once. Give it 15 s.
|
Follow-up commits addressing review:
Also merged |
This was referenced Nov 17, 2026
Sign in
to join this conversation on GitHub.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
Concurrent edits
updateRecipetakes an optionalexpectedUpdatedAt. The editor sends theupdatedAtit loaded.CONFLICTand overwrites nothing. The check runs under the row lockowned()already takes, and comparesupdatedAtin the format the API serves (milliseconds, UTC).Unsaved changes
beforeunload).useBlocker). This needs a data router, somain.tsxnow usescreateBrowserRouterwith one catch-all route that renders the existing<Routes>. Nothing else about routing changes.Drafts and sign-out
Return after login
/recipes/<id>/editwhile logged out now returns to that editor after login. Only exact/recipes/<uuid>/editpaths are accepted; everything else still falls back to/.Validation
npm run checkpasses (284 unit tests). New tests:expectedUpdatedAt, and onCONFLICTthe form keeps its contents and shows the messagebeforeunloadis cancelled only while changes are unsaved (not after Save draft)countUserDrafts()test:api(PostgreSQL 16): tab A saves, tab B's save from the old version getsCONFLICTand the title stays as tab A saved it; saving with the current version, or without one, works.AI usage
Written with Claude Code (Anthropic) to address a teammate's issue. Please review the diff as you would any other contribution.
Closes #121